package baidu;
import com.baidu.aip.ocr.*;
import java.util.HashMap;

import org.json.*;

public class ReportScanner {
    //设置APPID/AK/SK
    public static final String APP_ID ="10897480";
    public static final String API_KEY ="KTdyKjgGjL2OlFY1gSTSO5rl";
    public static final String SECRET_KEY ="69FHS1qjtVKR796oU0pIRsoprvyV0IVP";
    public static void main(String[] args) {
// 初始化一个OcrClient
        AipOcr client = new com.baidu.aip.ocr.AipOcr(APP_ID, API_KEY, SECRET_KEY);
// 可选：设置网络连接参数
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);
        String file = "b:\\中航重机财务报表.pdf";
        JSONObject res = client.tableRecognitionAsync(file,new HashMap<String, String>());
        String reqId = res.getJSONArray("result").getJSONObject(0).getString("request_id");
        JSONObject jsonres = client.tableRecognizeToJson(file, 20000);
        System.out.println(jsonres.toString(2));
        JSONObject excelres = client.tableRecognizeToExcelUrl(file, 20000);
        System.out.println(excelres.toString(2)) ;
    }
}